//
//  LogoViewController.m
//  Quiz
//
//  Created by Ha Cong Thuan on 3/26/14.
//  Copyright (c) 2014 Ha Cong Thuan. All rights reserved.
//

#import "LogoViewController.h"

@interface LogoViewController ()

@end

@implementation LogoViewController{
    LogoCollectionCell *cell;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
    [self getJsonValue];
}
-(void)getJsonValue{
    arrLogo =[[NSMutableArray alloc]init];
    [DejalBezelActivityView activityViewForView:self.view];
    NSString *url=Sub_Categories;
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    url=[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSArray *feedjsons=[responseObject objectForKey:@"data"] ;
        for (NSDictionary *tem in feedjsons) {
            NSDictionary *SubCategory=[tem objectForKey:@"SubCategory"];
            SubCategoriesModel *model=[[SubCategoriesModel alloc]innitWithJson:SubCategory];
            [arrLogo addObject:model];
        }
        
        [DejalBezelActivityView removeView];
        [collectionview reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        [DejalBezelActivityView removeView];
    }];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
//    [self performSegueWithIdentifier:@"logoDetail" sender:self];
    // Dispose of any resources that can be recreated.
}
#pragma mark Conllectionview

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return  1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return arrLogo.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
   cell = (LogoCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    
    //Cell configure
    SubCategoriesModel *model = [arrLogo objectAtIndex:indexPath.row];
    cell.logoModel = model;
    [cell loadImage];
    return cell;
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
        [self performSegueWithIdentifier:@"logoSub" sender:nil];
//    LogoDetailViewController *vc=[self.storyboard instantiateViewControllerWithIdentifier:@"lodoDetail"];
//    SubCategoriesModel *model = [arrLogo objectAtIndex:indexPath.row];
//    vc.subModel= model;
//    [self.navigationController pushViewController:vc animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
